//
//  FreeCerMagmentViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/14.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "FreeCerMagmentViewModel.h"
#import "FreeCerManagementTableViewHeaderFooterView.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "AutherEmterpriseTableViewCell.h"
#import "NameAndPositionTableViewCell.h"
#import "SelfIdCardTableViewCell.h"

@interface FreeCerMagmentViewModel ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray * titArr;
}
@end

@implementation FreeCerMagmentViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        titArr = @[@"请输入真实姓名",@"请输入身份证号"];
        tableView.mj_header.hidden = YES;
        tableView.mj_footer.hidden = YES;
        tableView.delegate = self;
        tableView.dataSource = self;
        [tableView registerClass:[FreeCerManagementTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"FreeCerManagementTableViewHeaderFooterView"];
        [tableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        [superView addSubview:tableView];
    }
    return self;
}

#pragma mark -- <UITableViewDelegate,UITableViewDataSource>
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else{
        return 3;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat cellHeighr = 0.01;
    switch (indexPath.section) {
        case 0:{
            cellHeighr = UITableViewAutomaticDimension;
        }
            break;
        case 1:{
            if (indexPath.row == 2) {
                cellHeighr = UITableViewAutomaticDimension;
            }else{
                cellHeighr = kHeightProportion_In_iPhoneTriploid(44);
            }
        }
            break;
            
        default:
            break;
    }
    return cellHeighr;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseTableViewCell * cell;
    switch (indexPath.section) {
        case 0:{
            NameAndPositionTableViewCell * cell_pos = [NameAndPositionTableViewCell cellWithTableView:tableView];
            cell_pos.Block_namePositionComint = ^{
                
            };
            cell = cell_pos;
        }
            break;
        case 1:{
            if (indexPath.row == 2) {
                SelfIdCardTableViewCell * cell_idCard = [SelfIdCardTableViewCell cellWithTableView:tableView];
                cell_idCard.Block_idCardComint = ^{
                    [self requestNetData];
                };
                cell = cell_idCard;
            }else{
                AutherEmterpriseTableViewCell * cell_emter = [AutherEmterpriseTableViewCell cellWithTableView:tableView];
                cell_emter.placeholderStr = titArr[indexPath.row];
                cell_emter.indexPath = indexPath;
                [cell_emter setSepartionLineWith:lineModel_Half];
                cell = cell_emter;
            }
        }
            break;
            
        default:
            break;
    }
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    FreeCerManagementTableViewHeaderFooterView * headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"FreeCerManagementTableViewHeaderFooterView"];
    if (section == 0) {
        headerView.leftLabel.text = @"身份认证";
    }else{
        headerView.leftLabel.attributedText = [GLGWLabel bllChangeStr:@"实名认证  通过后可提现" changewithStr:@"通过后可提现" changeColoer:kColor_Rule_Yellow withFont:SYSTEMFONT(12)];
    }
    return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return kHeightProportion_In_iPhoneTriploid(30);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * footView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return footView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

#pragma mark --- 数据请求
-(void)requestNetData{
    NSDictionary * parDic = @{@"username":@"18301698947",
                              @"realName":@"杨礼军",
                              @"idCardNum":@"67543346777654343323",//需要校
                              @"idCardPic1":@"http://www.hui-ben.com/qingdao3/20131030/news_img/20131211164053.jpg",
                              @"idCardPic2":@"http://alipic.files.mozhan.com/ueditor/image/20170624/1498303396330392.jpg"};
    [GLGWRequestTool POST:[NSString stringWithFormat:@"%@%@",kApiPrefix,kAdduserdetailsinfo] lodingView:nil lodingTextString:@"" isLoding:YES parameters:parDic success:^(id  _Nullable response) {
        
    } failure:^(NSError * _Nullable error) {
        
    }];
}
@end
